package com.rzgeo.rzmaplib.comp;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.ListView;

import com.esri.arcgisruntime.data.FeatureTable;
import com.esri.arcgisruntime.data.Field;
import com.rzgeo.rzmaplib.R;

/**
 * Created by zhanghang on 2018/2/5.
 */

public class RmlSlideList extends FrameLayout {
    private ListView lvMarkers;
    private View btnAdd;
    private View btnMinus;
    private View btnClear;
    private FeatureTable _ft;

    private FeatureTable _slideGroupLine;
    private FeatureTable _slideViewPon;

    public static class GroupLineBean{
        public static Field FOid;

        public static Field FMsg;
        public static Field FEditTim;
        public static Field FCreator;
        public static Field FCreateTim;
        private static Field FGroupid;
        public long oid;
        public String Msg;

        public static void initField(FeatureTable table) {
            if(GroupLineBean.FOid ==null){
                for (Field f:table.getFields()){
                    if(f.getFieldType()== Field.Type.OID){
                        GroupLineBean.FOid =f;
                    }
                    else if("Groupid".equalsIgnoreCase(f.getName())){
                        GroupLineBean.FGroupid =f;
                    }
                    else if("Msg".equalsIgnoreCase(f.getName())){
                        GroupLineBean.FMsg =f;
                    }
                    else if("EditTim".equalsIgnoreCase(f.getName())){
                        GroupLineBean.FEditTim =f;
                    }
                    else if("Creator".equalsIgnoreCase(f.getName())){
                        GroupLineBean.FCreator =f;
                    }
                    else if("CreateTim".equalsIgnoreCase(f.getName())){
                        GroupLineBean.FCreateTim =f;
                    }
                }
            }
        }
    }


    public static class ViewPonBean{
        public static Field FOid;

        public static Field FMsg;
        public static Field FEditTim;
        public static Field FCreator;
        public static Field FCreateTim;
        public static Field FGroupid;
        public static Field FRoll;
        public static Field FDist;
        public static Field FTile;
        public static Field FPitch;
        public long oid;
        public String Msg;

        public static void initField(FeatureTable table) {
            if(ViewPonBean.FOid ==null){
                for (Field f:table.getFields()){
                    if(f.getFieldType()== Field.Type.OID){
                        ViewPonBean.FOid =f;
                    }
                    else if("Groupid".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FGroupid =f;
                    }
                    else if("Msg".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FMsg =f;
                    }
                    else if("EditTim".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FEditTim =f;
                    }
                    else if("Creator".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FCreator =f;
                    }
                    else if("CreateTim".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FCreateTim =f;
                    }
                    else if("Roll".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FRoll =f;
                    }
                    else if("Tile".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FTile =f;
                    }

                    else if("Pitch".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FPitch =f;
                    }

                    else if("Dist".equalsIgnoreCase(f.getName())){
                        ViewPonBean.FDist =f;
                    }




                }
            }
        }
    }

    public RmlSlideList(Context context) {
        super(context);
        initUI(context);
    }

    public RmlSlideList(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initUI(context);
    }

    public RmlSlideList(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initUI(context);
    }

    private void initUI(Context context) {
        View subView = LayoutInflater.from(context).inflate(R.layout.comp_slide_list, null);
        subView.setLayoutParams(
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        this.addView(subView);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        btnAdd=findViewById(R.id.btn_add);
        btnMinus=findViewById(R.id.btn_minus);
        btnClear=findViewById(R.id.btn_clear);

        btnAdd.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        btnMinus.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        btnClear.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        lvMarkers=findViewById(R.id.lv_markers);
        lvMarkers.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    }

    public void setup(FeatureTable slideGroupLine, FeatureTable slideViewPon) {
        _slideGroupLine=slideGroupLine;
        _slideViewPon=slideViewPon;
    }
}
